<template>
  <div class="normal-setting-box">
    <div class="smart-plan-landing-top mar-b-12" :style="topBgStyle">
      <div class="smart-plan-landing-top__left">
        <div class="top-title1 mar-b-8">{{$t('face.recognition')}}</div>
        <div class="top-title2 mar-b-8">{{$t('face.recognitionInfo')}}</div>
          <el-button type='plain-third' @click="openDescriptionItem"> {{$t('task.setting.taskTypeSetting.flow.components.title22')}}</el-button>
      </div>
      <div class="smart-plan-landing-top__right">
        <img :src="img1" />
      </div>
    </div>
    <div class="user-card-setting">
      <el-row class="box-item im-setting" :gutter="15" style="margin-top:0;margin-bottom: 0">
        <el-col :span="16">
          <p class="item-title">{{$t('face.settingFaceRecognitionInfo')}}</p>
          <p class="item-text">{{$t('face.settingFaceRecognitionInfoDes')}}</p>
        </el-col>
        <el-col :span="8" class="user-card-switch">
          <el-switch
            class="setting—box-switch"
            v-model="showChangeFaceImg"
            @change="handleChangeShowChangeFaceImg"
            :active-color="getThemeColor">
          </el-switch>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import * as settingApi from '@src/api/SettingApi'
const FACE_RECOGNITION = 'isReUploadUserFace'
import { getOssUrl } from '@src/util/assets'
import platform from '@src/platform'
const img1 = getOssUrl('/face_recognition_banner_img.png')
export default {
  data() {
    return {
      img1,
      showChangeFaceImg: false
    }
  },
  computed: {
    topBgStyle() {
      return {
          background: `url(${getOssUrl('/face_recognition_bg.png')}) no-repeat center`
      }
    }
  },
  created(){
    this.fetchConfig()
  },
  methods: {
    openDescriptionItem() {
      platform.openLink('https://doc.shb.ltd/shb_xoqazk/ia4qctp2ly559d1m/gre7yumc5sz4ewod/bsgu1tcmhno6r86e.html')
    },
    async fetchConfig() {
      try {
        const { data = [], success, message } = await settingApi.getTenantConfigByCodeList({ codeList: [FACE_RECOGNITION] })
        if(!success) return this.$message.error(message)
        this.showChangeFaceImg = !!data.find(item=> item.configCode === FACE_RECOGNITION)?.isOpen
      } catch(err) {
        console.error('[getTenantConfigByCodeList error]', err)
      }
    },
    async handleChangeShowChangeFaceImg(v) {
      try {
        const { success, message = '' } = await settingApi.updateTenantConfigById({ code:FACE_RECOGNITION, isOpen: Number(v), configNumValue: 0})
        if(!success) {
          this.$message.error(message)
        }
      } catch(err) {
        console.error('[updateTenantConfigById error]', err)
      }

    }
  }
}
</script>

<style lang="scss" scoped>
.normal-setting-box{
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 12px;
  height: 100vh;
    .smart-plan-landing-top {
    height: 220px;
    // background: url('@src/assets/img/smartPlan/bg.png') no-repeat center;
    background-size: contain;
    display: flex;
    justify-content: space-between;
    padding: 27px 48px 9px 23px;
    position: relative;
    &__left {
      width: 70%;
    }
    .top-title1 {
      font-size: 36px;
      font-weight: bold;
      @include text-ellipsis();
    }
    .top-title2 {
      font-size: 18px;
      color: #8C8C8C;
      @include text-ellipsis-2();
    }
    &__right {
      img {
        position: absolute;
        right: 48px;
        top: 0;
        height: 100%;
      }
    }
  }
}
.user-card-setting{
  width: 100%;
  padding:16px;
  border-radius: 16px;
  background: #ffffff;
  overflow-y: auto;
  // height:100%;
  .box-item{
    display: flex;
    align-items: center;
    margin-bottom: 36px;
    color:#262626;
    &.user-card-box{
      align-items: flex-start;
    }
    p{
      margin:0;
      padding:0;
    }
    .item-title{
      font-size: 14px;
      font-weight: bold;
      line-height: 18px;
    }
    .item-text,.item-content{
      font-size: 14px;
      line-height: 28px;
      margin-top: 5px;
      color:#8c8c8c;
    }
    .user-card-switch{
      text-align: right;
    }

  }
  .user-card-demo{
    position: relative;
    top: 0!important;
    margin-top:12px;
  }
  .danger-text{
    color:$color-danger!important;
  }
}
</style>